package com.voute.Presenter.Impl;


import android.text.TextUtils;

import com.voute.Model.Bean.BaseBean;
import com.voute.Model.Bean.InitAppBean;
import com.voute.Model.IAppInitModel;
import com.voute.Model.Impl.AppInitModelImpl;
import com.voute.Presenter.IAppInitPresenter;
import com.voute.Utils.CommonSubscriber;
import com.voute.Utils.TransformUtils;
import com.voute.View.IView.ISplashView;

/**
 * App 启动 初始化信息Model接口实现类
 * Created by liukanshan on 2016/12/30.
 */

public class AppInitPresenterImpl implements IAppInitPresenter {

    private ISplashView iView;
    private IAppInitModel iModel;

    public AppInitPresenterImpl(ISplashView view) {
        iView = view;
        iModel = new AppInitModelImpl();
    }


    @Override
    public void initApp() {
        iModel.initApp().compose(TransformUtils.<InitAppBean>defaultSchedulers()).subscribe(new CommonSubscriber<InitAppBean>() {
            @Override
            public void onSuccess(InitAppBean response) {
                iView.saveRSAPublicKey(response.getData().getPublic_key());
                String url_download = response.getData().getApp().getLink();
                String base_url = "https://" + response.getData().getServer() + "/";
//                Constants.SetBaseUrl(base_url);
                if (!TextUtils.isEmpty(response.getData().getBoot().getPic())) {
//                    iView.showWelcomeImage(response.getData().getBoot().getPic());
                }
                if("none".equals(response.getData().getApp().getOp())){
                    iView.enterApp();
                }
                else if("force".equals(response.getData().getApp().getOp())){
                    iView.showForceUpdateDialog(url_download);
                }
                else if("optional".equals(response.getData().getApp().getOp())){
                    iView.showOptionalUpdateDialog(url_download);
                }
            }
            @Override
            public void onFailure(BaseBean response) {

            }
        });
    }
}
